package com.fzy.modules.goods.web;

import com.fzy.core.common.ApiController;
import com.fzy.core.common.ResponseData;
import com.fzy.modules.goods.entity.GoodsUnit;
import com.fzy.modules.goods.service.GoodsUnitService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单位计量Controller
 * */
@RestController
@RequestMapping(value = "/api/goods/unit")
public class GoodsUnitController extends ApiController {
    @Autowired
    private GoodsUnitService goodsUnitService;
    @GetMapping (value = "")
    public List<GoodsUnit> list(){
        return goodsUnitService.findAllList();
    }
    @PostMapping(value = "")
    public ResponseEntity<ResponseData> save( GoodsUnit goodsUnit) {
        if (StringUtils.isNotEmpty(goodsUnit.getId())) {
            return new ResponseEntity<>(success(goodsUnitService.update(goodsUnit)), HttpStatus.OK);
        }

        return new ResponseEntity<>(success(goodsUnitService.save(goodsUnit)), HttpStatus.OK);
    }
    @DeleteMapping(value = "/{id}")
    public ResponseEntity<ResponseData> delete(@PathVariable String id) {
        return new ResponseEntity<>(success(goodsUnitService.delete(id)), HttpStatus.OK);
    }
}
